package com.it.ems.mapper;

import com.it.ems.entity.UserRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Delete;

import java.util.List;

@Mapper
public interface UserRoleMapper {
    @Select("SELECT * FROM user_roles WHERE user_id = #{userId}")
    List<UserRole> findByUserId(Long userId);
    
    @Select("SELECT * FROM user_roles WHERE role_id = #{roleId}")
    List<UserRole> findByRoleId(Long roleId);
    
    @Insert("INSERT INTO user_roles (user_id, role_id, created_at, updated_at) " +
            "VALUES (#{userId}, #{roleId}, NOW(), NOW())")
    int insert(UserRole userRole);
    
    @Delete("DELETE FROM user_roles WHERE id = #{id}")
    int delete(Long id);
    
    @Delete("DELETE FROM user_roles WHERE user_id = #{userId}")
    int deleteByUserId(Long userId);
    
    @Delete("DELETE FROM user_roles WHERE role_id = #{roleId}")
    int deleteByRoleId(Long roleId);
} 